home *** CD-ROM | disk | FTP | other *** search
/ MacHome 2001 May / MacHome CD (May 2001).iso / mac / Stuff / Software / Tools / Black & Bleu™ 3.0 / For Developers / Usage Example / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-28  |  5.0 KB  |  165 lines  |  [TEXT/CWIE]

  1. /*    main.c - This file demonstrates how to call
  2.                     the Bleu Rose Ltd. Error Library
  3.  
  4.     Copyright 2000 Bleu Rose Ltd. All Rights Reserved.
  5.  
  6.     Author:        Gary Rice
  7.  
  8.     Created:    September 9, 2000 - Development environment:
  9.                     CodeWarrior/Pro v5.3
  10.                     Mac OS v7.6.1
  11.  
  12.     Modified:    N/A
  13.  
  14.     Licensing Notes:
  15.         You may incorporate this source code into your
  16.         applications without restriction.
  17.  
  18.         You are NOT permitted to redistribute the source,
  19.         compiled binaries or the library that the code
  20.         references without first licensing the package
  21.         represented by this source file from Bleu Rose Ltd.
  22.  
  23.         Licensing information was packaged with the files
  24.         that this file was part of. If that licensing information
  25.         is no longer included in the files you have, you may obtain
  26.         another copy by sending EMail to licensing@bleurose.com
  27.         and asking for the Error Library Licensing Package.
  28.  
  29.     Usage Notes:
  30.         This file is compatible with Universal Headers v3.2 and later..
  31.         It assume MacHeaders.h is the default include file.
  32.  
  33. *****************************************************************/
  34.  
  35. /* Include the Error definition interface file */
  36. #include "BleuRoseErrors.h"
  37.  
  38. /* Prototypes */
  39. void     Initialize    (void);
  40. int        main         (void);
  41.  
  42. /* Here's all you have to do */
  43. int main (void)
  44. {
  45.     FSSpec                        theErrorLibrary;
  46.     BleuRoseErrorLibStructure    theError;
  47.     OSStatus                    result;
  48.     Str255                        p1;
  49.     Str255                        p2;
  50.     Str255                        p3;
  51.     Str255                        p4;
  52.     
  53.     Initialize();    /* Standard stuff */
  54.     
  55.     /* Locate the Bleu Rose Error Library */
  56.     result = FindBleuRoseErrorLibrary (&theErrorLibrary);
  57.     
  58.     /* If we found the library, look up the rquested error */
  59.     if (result == (OSStatus)noErr)
  60.     {
  61.         /*-------------- v Your Code Goes Here v -------------------------------------------
  62.         The following 2 lines of code are the only things you really need
  63.         to fill in from your own source. The first is the actual error you
  64.         want to look up. The second is the Error Type you think might be
  65.         the source of the error. If you don't know, just fill in a zero.
  66.         An error type would be a "QuickTime", "Location Manager",
  67.         "File System", etc. error. Many Mac OS error numbers have multiple
  68.         meanings. This error type value helps distinguish one from another. */
  69.         theError.error = -199;                                    /* Replace this # with your
  70.                                                                     own error value */
  71.         theError.proposedErrorTypeNumber = k1stErrorTypeFound;    /* Find the first 
  72.                                                                     occurrence of the error
  73.         ----------------- ^ Your Code Goes Here ^ ----------------------------------------- */
  74.         
  75.         /* Look the error up */
  76.         theError.action = kGetError;
  77.         result = CallBleuRoseErrorLibrary (&theErrorLibrary, &theError);
  78.     }
  79.     
  80.     /* If there was a problem, say so. Otherwise, set up to display the
  81.         error that was found in the library */
  82.     BlockMoveData ("\perror", p4, 6);
  83.     if (result)
  84.     {
  85.         /* Was it a system error or a Library error? */
  86.         if (result < kWarningLibraryNotLicensed &&    /* smallest Bleu Rose warning value */
  87.             result > kErrorNoDescResMissing)        /* largest Bleu Rose Error value */
  88.         {
  89.             BlockMoveData ("\pthere was a problem accessing the Bleu Rose Error Library", p1, 58);
  90.             BlockMoveData ("\pMac OS", p3, 7);
  91.         }
  92.         else
  93.         {
  94.             BlockMoveData ("\pBleu Rose Library", p3, 18);
  95.             switch (result)
  96.             {
  97.                 case kWarningErrorNotRequestedType:
  98.                     BlockMoveData ("\pthe error doesn't match the type requested", p1, 43);
  99.                     break;
  100.                 case kWarningErrorNotDescribed:
  101.                     BlockMoveData ("\pthe error has no description", p1, 29);
  102.                     break;
  103.                 case kWarningErrorNotDescribedAndNotRequestedType:
  104.                     BlockMoveData ("\pthe error is not the type you requested and the error has no description", p1, 73);
  105.                     break;
  106.                 case kWarningLibraryNotLicensed:
  107.                     BlockMoveData ("\pthe library has not yet been licensed", p1, 38);
  108.                     break;
  109.  
  110.                 case kErrorNotOnFile:
  111.                     BlockMoveData ("\pthe error requested was not found", p1, 34);
  112.                     break;
  113.                 case kErrorTypeOutOfRange:
  114.                     BlockMoveData ("\pthe error type you requested is not valid", p1, 42);
  115.                     break;
  116.                 case kErrorTypeNotOnFile:
  117.                     BlockMoveData ("\pthe error type requested was not found", p1, 39);
  118.                     break;
  119.                 case kErrorTypeResMissing:
  120.                     BlockMoveData ("\pthe error type STR# resource is missing", p1, 40);
  121.                     break;
  122.                 case kErrorResMissing:
  123.                     BlockMoveData ("\pthe error TEXT resource is missing. The library has probably NOT been populated", p1, 80);
  124.                     break;
  125.                 case kErrorNoDescResMissing:
  126.                     BlockMoveData ("\pthe 'no description' resource is missing", p1, 41);
  127.                     break;
  128.             }
  129.         }
  130.         
  131.         if (result > 0)
  132.             BlockMoveData ("\pwarning", p4, 8);
  133.         
  134.         NumToString (result, p2);
  135.         ParamText (p1, p2, p3, p4);
  136.     }
  137.     else
  138.     {
  139.         NumToString (theError.error, p2);
  140.         ParamText (theError.description, p2, theError.errorTypeName, p4);
  141.     }
  142.  
  143.     /* Display the error found or the failure message */
  144.     Alert (128, 0L);
  145.     return 0;    
  146. }
  147.  
  148. /*    Initialize the standard Mac OS Managers */
  149. void Initialize (void)
  150. {
  151. #if TARGET_API_MAC_CARBON
  152.     MoreMasters ();
  153. #else
  154.     MaxApplZone ();
  155.     MoreMasters ();
  156.  
  157.     InitGraf (&qd.thePort);
  158.     InitFonts ();
  159.     InitWindows ();
  160.     InitMenus ();
  161.     TEInit ();
  162.     InitDialogs (nil);
  163. #endif
  164.     InitCursor ();
  165. }